SceneManager = {
    stack = {},
    methods = {"keypressed", "mousepressed", "update", "draw"},

    push = function(scene)
        scene = scene .. "Scene"

        if loadstring("return type(" .. scene .. ")")() == "nil" then
            require("scenes/" .. scene)
        end

        scene = loadstring("return " .. scene .. ":new()")()
        table.insert(SceneManager.stack, 0, scene)
    end,

    pop = function()
        table.remove(SceneManager.stack, 0)
    end,

    top = function()
        return SceneManager.stack[0]
    end
}

for _, method in ipairs(SceneManager.methods) do
    SceneManager[method] = function(...)
        local top = SceneManager.top()
        top[method](top, unpack(arg))
    end
end
